﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataAccess.Object
{
    public class SanPhamDAO
    {
        DataAccess _conn = new DataAccess();
        public DataTable DS_SP(string id)
        {
            SqlParameter[] pram = new SqlParameter[1];


            pram[0] = new SqlParameter("@id", SqlDbType.NVarChar);
            pram[0].Value = id;
            return _conn.ExecuteDataTable("DS_SP_Byid", pram);
        }
        public DataTable DS_SP_byname(string tensp)
        {
            SqlParameter[] pram = new SqlParameter[1];


            pram[0] = new SqlParameter("@tensp", SqlDbType.NVarChar);
            pram[0].Value = tensp;
            return _conn.ExecuteDataTable("DS_SP",pram);
        }
        public DataTable TenSP()
        {
            return _conn.ExecuteDataTable("TenSP");
        }
        public DataTable idNhanvien(string tennv)
        {
            SqlParameter[] pram = new SqlParameter[1];


            pram[0] = new SqlParameter("@tennv", SqlDbType.NVarChar);
            pram[0].Value = tennv;
            return _conn.ExecuteDataTable("IDNhanVien",pram);
        }
        public DataTable MaSP(string tensp)
        {
            SqlParameter[] pram = new SqlParameter[1];

            pram[0] = new SqlParameter("@ten_sp", SqlDbType.NVarChar);
            pram[0].Value = tensp;
            return _conn.ExecuteDataTable("MaSP", pram);
        }
        

        public void suaSanPham(SanPhamOB sp)
        {
            SqlParameter[] pram = new SqlParameter[9];

            pram[0] = new SqlParameter("@ma_sp", SqlDbType.NVarChar);
            pram[0].Value = sp.ma_sp;
            pram[1] = new SqlParameter("@ten_sp", SqlDbType.NVarChar);
            pram[1].Value = sp.ten_sp;
            pram[2] = new SqlParameter("@gioithieu_sp", SqlDbType.NVarChar);
            pram[2].Value = sp.gioithieu_sp;
            pram[3] = new SqlParameter("@soluong_sp", SqlDbType.Int);
            pram[3].Value = sp.soluong_sp;
            pram[4] = new SqlParameter("@soluong_cl", SqlDbType.Int);
            pram[4].Value = sp.soluong_cl;
            pram[5] = new SqlParameter("@gia_sp", SqlDbType.Int);
            pram[5].Value = sp.gia_sp;
            pram[6] = new SqlParameter("@nhacungcap_sp", SqlDbType.NVarChar);
            pram[6].Value = sp.nhacungcap_sp;
            pram[7] = new SqlParameter("@hopdongso_sp", SqlDbType.NVarChar);
            pram[7].Value = sp.hopdongso_sp;
            pram[8] = new SqlParameter("@donvitinh_sp", SqlDbType.NVarChar);
            pram[8].Value = sp.donvitinh_sp;
            _conn.ExecuteNonQuery("SuaSanPham", pram);
        }

        
        public DataTable DanhSachSP()
        {
            return _conn.ExecuteDataTable("DanhSachSP",null);
        }


        public DataTable SanPham_By_Id(string ma_sp)
        {
            SqlParameter[] pram = new SqlParameter[1];
            pram[0] = new SqlParameter("@ma_sp", SqlDbType.NVarChar);
            pram[0].Value = ma_sp;
            return _conn.ExecuteDataTable("SanPham_By_Id", pram);
        }


        public void xoaSP_DH(string id)
        {
            SqlParameter[] pram = new SqlParameter[1];

            pram[0] = new SqlParameter("@ma_dh", SqlDbType.NVarChar);
            pram[0].Value = id;  
        }

        public DataTable danhsachspbyid(string ma_sp)
        {
            SqlParameter[] pram = new SqlParameter[1];
            pram[0] = new SqlParameter("@ma_sp", SqlDbType.NVarChar);
            pram[0].Value = ma_sp;
            return _conn.ExecuteDataTable("DanhSachSPbyid", pram);
        }

        public DataTable TimKiemsp(string where)
        {
            SqlParameter[] pram = new SqlParameter[1];
            pram[0] = new SqlParameter("@whereCondition", SqlDbType.NVarChar);
            pram[0].Value = where;
            return _conn.ExecuteDataTable("TimKiemSP", pram);
        }

        
        public void themSP(SanPhamOB sp)
        {
            SqlParameter[] pram = new SqlParameter[9];


            pram[0] = new SqlParameter("@ma_sp", SqlDbType.NVarChar);
            pram[0].Value = sp.ma_sp;
            pram[1] = new SqlParameter("@ten_sp", SqlDbType.NVarChar);
            pram[1].Value = sp.ten_sp;
            pram[2] = new SqlParameter("@gioithieu_sp", SqlDbType.NVarChar);
            pram[2].Value = sp.gioithieu_sp;
            pram[3] = new SqlParameter("@soluong_sp", SqlDbType.Int);
            pram[3].Value = sp.soluong_sp;
            pram[4] = new SqlParameter("@soluong_cl", SqlDbType.Int);
            pram[4].Value = sp.soluong_sp;
            pram[5] = new SqlParameter("@gia_sp", SqlDbType.Int);
            pram[5].Value = sp.gia_sp;
            pram[6] = new SqlParameter("@nhacungcap_sp", SqlDbType.NVarChar);
            pram[6].Value = sp.nhacungcap_sp;
            pram[7] = new SqlParameter("@hopdongso_sp", SqlDbType.NVarChar);
            pram[7].Value = sp.hopdongso_sp;
            pram[8] = new SqlParameter("@donvitinh_sp", SqlDbType.NVarChar);
            pram[8].Value = sp.donvitinh_sp;
            _conn.ExecuteNonQuery("ThemSanPham", pram);
        }

        

        public void xoaSanPham(string ma_sp)
        {
            SqlParameter[] pram = new SqlParameter[1];

            pram[0] = new SqlParameter("@ma_sp", SqlDbType.NVarChar);
            pram[0].Value = ma_sp;
            _conn.ExecuteNonQuery("XoaSanPham", pram);
        }
    
    }
}
